const express = require("express");
const path = require("path");
const router = express.Router();
const url = require("url");

const InspireCloud = require("@byteinspire/js-sdk");
const serviceId = "qcshgh"; // 替换serviceId

// 初始化
const inspirecloud = new InspireCloud({ serviceId });

router.post("/login", (req, res) => {
  const { username, password } = req.body;
  inspirecloud
    .run("exist_user", { username, password })
    .then((data) => {
      const { result } = data;
      console.log(result);
      if (result.length > 0) {
        res.send({
          nickname: result[0].username,
          type:result[0].type,
          status: 200,
        });
      } else {
        res.send({
          status: 400,
          msg: "用户名错误或密码错误",
        });
      }
    })
    .catch((err) => {
      console.log(err);
    });
});

module.exports = router;
